package GUILayer;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextField;

import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.UIManager;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.lang.*;
import java.lang.Integer.*;
import CtrLayer.SchemeCtr;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Temperature extends JFrame {

	private JPanel contentPane;
	private SchemeCtr schemeCtr;
	private JTextField temperature;
	private JTextField time;
	private JTextField pulse;
	private JTextField schema_name;
	private JTextField respiration;
	private JTextField blood_pressure1;
	private String datetime;
	private JTextField blood_pressure2;
	
	
	public static void main (String [] args)
	{
		
		
		new  Temperature(new JLabel(),new DefaultTableModel());
	}
	

	/**
	 * Create the frame.
	 */
	public Temperature(final JLabel mainFrameLabel, final DefaultTableModel model) {
		setTitle("Create Temperature Schema");
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setBounds(100, 100, 420, 447);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
    	try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            setIconImage(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("b4/advancedgui/menu/resources/green_arrow_right.png")));
        } catch (Exception ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
           
        }
		
		schemeCtr=new SchemeCtr();
		
		Box horizontalBox = Box.createHorizontalBox();
		horizontalBox.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Measurements", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		horizontalBox.setBounds(0, 42, 404, 367);
		contentPane.add(horizontalBox);
		
		temperature = new JTextField();
		temperature.setBounds(156, 73, 99, 36);
		contentPane.add(temperature);
		temperature.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("Temperature:");
		lblNewLabel.setBounds(79, 84, 99, 14);
		contentPane.add(lblNewLabel);
		
		JButton chooseDate = new JButton("Choose date");
		chooseDate.setBounds(51, 268, 106, 23);
		contentPane.add(chooseDate);
		
		time = new JTextField();
		time.setBounds(284, 261, 99, 36);
		contentPane.add(time);
		time.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("Time:");
		lblNewLabel_1.setBounds(253, 272, 46, 14);
		contentPane.add(lblNewLabel_1);
		
		JButton createSchema = new JButton("Create schema");
		createSchema.setBounds(264, 364, 119, 23);
		contentPane.add(createSchema);
		
		final JLabel selectedDate = new JLabel("Date");
		selectedDate.setBounds(177, 272, 78, 14);
		contentPane.add(selectedDate);
		chooseDate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new SessionCalendar(selectedDate);
			}
		});
		
		pulse = new JTextField();
		pulse.setBounds(156, 120, 99, 36);
		contentPane.add(pulse);
		pulse.setColumns(10);
		
		JLabel lblValue = new JLabel("Pulse:");
		lblValue.setBounds(121, 131, 46, 14);
		contentPane.add(lblValue);
		
		JLabel lblTemperatureShcemaName = new JLabel("Temperature shcema name:");
		lblTemperatureShcemaName.setBounds(10, 17, 187, 20);
		contentPane.add(lblTemperatureShcemaName);
		
		schema_name = new JTextField();
		schema_name.setBounds(177, 9, 147, 36);
		contentPane.add(schema_name);
		schema_name.setColumns(10);
		
		respiration = new JTextField();
		respiration.setBounds(156, 167, 99, 36);
		contentPane.add(respiration);
		respiration.setColumns(10);
		
		JLabel lblNewLabel_3 = new JLabel("Respiration:");
		lblNewLabel_3.setBounds(89, 178, 124, 14);
		contentPane.add(lblNewLabel_3);
		
		JLabel lblNewLabel_5 = new JLabel("Blood pressure from:");
		lblNewLabel_5.setBounds(35, 225, 124, 14);
		contentPane.add(lblNewLabel_5);
		
		blood_pressure1 = new JTextField();
		blood_pressure1.setBounds(156, 214, 99, 36);
		contentPane.add(blood_pressure1);
		blood_pressure1.setColumns(10);
		
		JLabel lblNewLabel_6 = new JLabel("To:");
		lblNewLabel_6.setBounds(264, 225, 29, 14);
		contentPane.add(lblNewLabel_6);
		
		blood_pressure2 = new JTextField();
		blood_pressure2.setColumns(10);
		blood_pressure2.setBounds(284, 214, 99, 36);
		contentPane.add(blood_pressure2);
		//preparing variables for creating schema

		setVisible(true);
		createSchema.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try{
					datetime = selectedDate.getText() +" "+ time.getText();
					 int pulseInt = Integer.parseInt(pulse.getText());
					 int blood_pressure1Int = Integer.parseInt(blood_pressure1.getText());
					 int blood_pressure2Int = Integer.parseInt(blood_pressure2.getText());
					 int temperatureInt = Integer.parseInt(temperature.getText());
					 int respirationInt = Integer.parseInt(respiration.getText());
					
					schemeCtr.createTempScheme(schema_name.getText(),pulseInt ,blood_pressure1Int , blood_pressure2Int, datetime,temperatureInt , respirationInt);
				
				
					
					 String[] name={schema_name.getText()};
					 model.addRow(name);
					model.fireTableDataChanged();
	
				dispose();
				}
				
				catch(Exception ex)
				{
					System.out.println("Error while creating scale");
				}
			}
		});
	}

	

}